package com.chj.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.stereotype.Service;

import com.chj.constants.Constants;
import com.chj.dao.NetWorkDAO;
import com.chj.entity.NetWork;
import com.chj.mapper.NetWorkMapper;
import com.chj.service.NetWorkServcie;
import com.etc.jdbc.util.JDBCUtils;

@Service
public class NetWorkServiceImpl implements NetWorkServcie {

    @Resource
    private NetWorkDAO netWorkDAO;

    @Override
    public int addNetWork(NetWork netWork) {
        
        return netWorkDAO.Save(netWork);
    }


    @Override
    public boolean checkNetWorkRepeat(NetWork netWork) {

        return netWorkDAO.isNetWorkIsExist(netWork.getNetworkName());
    }


    @Override
    public int deleteNetWork(NetWork netWork) {

        return netWorkDAO.deleteNetwork(netWork.getNetworkId());
    }

    @Override
    public NetWork getNetWork(String netWorkId) {

        String sql = " SELECT * FROM t_network T where  T.network_id = ? ";

        return JDBCUtils.queryForObject(sql, new NetWorkMapper(), netWorkId);
    }

    @Override
    public List<NetWork> getNetWorkAllList() {
        
        return netWorkDAO.getNetworkAllList();
    }

    @Override
    public List<NetWork> getNetWorkListBy(Map<String, Object> queryMap,int page,int rows) {

        String  networkName      = MapUtils.getString(queryMap  ,"networkName");
        String networkParkSize   = MapUtils.getString(queryMap  ,"networkParkSize");
        String  networkProvince  = MapUtils.getString(queryMap  ,"networkProvince");
        String  networkCity      = MapUtils.getString(queryMap  ,"networkCity");
        String  networkArea      = MapUtils.getString(queryMap  ,"networkArea");
        String  networkPrice     = MapUtils.getString(queryMap  ,"networkPrice");
        String  networkTimeBegin = MapUtils.getString(queryMap  ,"networkTimeBegin");
        String  networkTimeEnd   = MapUtils.getString(queryMap  ,"networkTimeEnd");
        Integer networkType      = MapUtils.getInteger(queryMap ,"networkType");

        List<NetWork> netWorkList = netWorkDAO.getNetWorkList( networkName
                                                              ,NumberUtils.toInt(networkParkSize)
                                                              ,networkProvince 
                                                              ,networkCity     
                                                              ,networkArea     
                                                              ,networkPrice    
                                                              ,networkTimeBegin
                                                              ,networkTimeEnd  
                                                              ,networkType
                                                              ,page
                                                              ,rows);

        return netWorkList;
    }

    @Override
    public int modifyNetWork(String networkId, NetWork netWork) {

        return netWorkDAO.modifyNetwork(netWork);
    }


    @Override
    public int getNetworkListBy(Map<String, Object> queryMap) {
        
        return netWorkDAO.getNetWorkListSize("", 0, "", "", "", "", "", "", 1);
    }

}
